home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / atime89.arc / a_time89.c next >
C/C++ Source or Header  |  1989-05-25  |  7KB  |  206 lines

  1. /*  
  2.     AUTO - TIMESET Version 1.0 by Radoslav Bogdanovic / RadoSoft 
  3.             Compiled with Sozobon C -- 17 may, 1989
  4.             
  5.     For Microdeal Internal Clock Card and other clock cards working
  6.     on the keyboard processor for time & date maintaince.
  7.     
  8.     This program also takes over the function of the AUTOTIME.PRG which
  9.     is supplied with Microdeal Clock Card.
  10.     
  11.     For more details see the supplied documentation file.
  12.     
  13. */
  14.  
  15. #include <stdio.h>
  16. #include <ctype.h>
  17. #include <osbind.h>
  18.  
  19. main(argc,argv)
  20. int argc;
  21. char *argv[];
  22. {
  23.     register unsigned long IKBDtimedate;
  24.     register unsigned int GEMtime, GEMdate;
  25.     int seconds, minutes, hours, day, month, year, fyear;
  26.     char *ptr, ans;
  27.  
  28.     printf("\n      AUTO - TIMESET Version 1.0\n"); 
  29.     printf("   by Radoslav Bogdanovic / RadoSoft\n");
  30.     printf("Compiled with Sozobon C -- 12 May, 1989\n");
  31.  
  32.  
  33.     /* Following works only with Sozobon C, because other C compilers does
  34.        NOT inserts program name (command) in ARGV[0] when program started 
  35.        from GEM-DESKTOP or program autostarted from AUTO-folder.          */    
  36.     ptr = argv[0];
  37.     while (*ptr) ++ptr;     /* Find the end of the program name */
  38.     ptr -= 6;               /* Back up to xx.prg                */
  39.     if ( isdigit(*ptr) ) 
  40.         fyear = atoi(ptr);
  41.     else {
  42.         printf("\n This is %s ...\n",argv[0]);
  43.         printf(" This program should be renamed to\n"); 
  44.         printf(" A_TIMExx.PRG, where xx is 80 to 99,\n");
  45.         printf(" two digits indicating which year\n");
  46.         printf(" you want to check against. \n");
  47.         printf("\n Press any key to exit\n");
  48.         Bconin(2);
  49.         exit(0);
  50.     }
  51.  
  52.     IKBDtimedate = Gettime();
  53.     GEMtime = Tgettime();
  54.     GEMdate = Tgetdate();
  55.     
  56.     /* Check if year from filename is same as current IKBD year  */
  57.     /* If year from filename differs from current IKBD year then */
  58.     /* it's assumed that the IKBD time is wrong or zeroed.       */
  59.     
  60.     if (fyear != (((IKBDtimedate >> 25) & 0x7F) + 80)) {
  61.  
  62.         IKBDtimeprint("\nThe current IKBD time and date is",IKBDtimedate);
  63.         timeprintGEM("The current GEM time is",GEMtime);
  64.         dateprintGEM("The current GEM date is",GEMdate);
  65.  
  66.         printf("\nDo you want to change time and date (Y/N): ");
  67.         ans = Bconin(2);
  68.         if ((ans == 'Y')||(ans == 'y'))
  69.         {
  70.             printf("\nEnter the new date and time (YY/MM/DD HH:MM): ");
  71.             scanf("%d/%d/%d %d:%d",&year,&month,&day,&hours,&minutes);
  72.             seconds = 0;
  73.             if (year < 100) year += 1900;
  74.     
  75.             IKBDtimedate =  ((unsigned long)(year-1980)<<25)
  76.                             |((unsigned long)month<<21)
  77.                             |((unsigned long)day<<16)
  78.                             |((unsigned long)hours<<11)
  79.                             |((unsigned long)minutes<<5)
  80.                             |((unsigned long)seconds<<1);
  81.     
  82.             GEMdate = ((unsigned)(year - 1980)<<9)
  83.                      |((unsigned)month<<5)
  84.                      |(unsigned)day;        
  85.                      
  86.             GEMtime = ((unsigned)hours<<11)
  87.                      |((unsigned)minutes<<5)
  88.                      |((unsigned)seconds>>1); 
  89.           
  90.             Settime(IKBDtimedate);
  91.             Tsettime(GEMtime);
  92.             Tsetdate(GEMdate);
  93.         }
  94.         else 
  95.            setsystemtime(Gettime());
  96.         putchar('\n');    
  97.     }
  98.     else
  99.        setsystemtime(Gettime());        
  100. }
  101.  
  102. /*-----------------------------------------------------*/
  103. /* fixdigit insert a '0' before number if number < 10  */
  104. /*-----------------------------------------------------*/
  105. fixdigit(buf, number)
  106. char *buf; int number;
  107. {
  108.     if (number < 10) {
  109.         buf[0] = '0';
  110.         sprintf(&buf[1],"%d",number);
  111.     }    
  112.     else
  113.         sprintf(buf,"%d",number);        
  114. }                    
  115.  
  116. /*---------------------------------------------------------------*/
  117. /* IKBDtimeprint decodes IKBD time & date  and prints a string   */
  118. /*---------------------------------------------------------------*/
  119. IKBDtimeprint(string,time)
  120. char *string; register unsigned long time;
  121. {
  122.     int seconds, minutes, hours, day, month, year;
  123.     char mins[3], secs[3], days[3], monts[3];
  124.     
  125.     seconds = (time & 0x001F) << 1;
  126.     minutes = (time >> 5) & 0x3F;
  127.     hours   = (time >> 11) & 0x1F;
  128.     
  129.     day     = (time >> 16) & 0x1F;
  130.     month   = (time >> 21) & 0x0F;
  131.     year    = ((time >> 25) & 0x7F) + 1980;
  132.     
  133.     fixdigit(mins, minutes);
  134.     fixdigit(secs, seconds);
  135.     fixdigit(days, day);
  136.     fixdigit(monts, month);
  137.     printf("%s %d:%s:%s on %d/%s/%s\n",string,hours,mins,
  138.             secs, year,monts,days);
  139. }                       
  140.  
  141. /*-----------------------------------------------------*/
  142. /* timeprintGEM decodes GEM time and prints a string   */
  143. /*-----------------------------------------------------*/
  144. timeprintGEM(string,time)
  145. char *string; register unsigned int time;
  146. {
  147.     int seconds, minutes, hours;
  148.     char mins[3], secs[3];
  149.     
  150.     seconds = (time & 0x001F) << 1;
  151.     minutes = (time >> 5) & 0x3F;
  152.     hours   = (time >> 11) & 0x1F;
  153.     
  154.     fixdigit(mins, minutes);
  155.     fixdigit(secs, seconds);
  156.     printf("%s %d:%s:%s\n",string,hours,mins,secs);
  157. }
  158.  
  159. /*-----------------------------------------------------*/
  160. /* dateprintGEM decodes GEM date and prints a string   */
  161. /*-----------------------------------------------------*/
  162. dateprintGEM(string,date)
  163. char *string; register unsigned int date;
  164. {
  165.     int day, month, year;
  166.     char days[3], monts[3];
  167.     
  168.     day     = date & 0x1F;
  169.     month   = (date >> 5) & 0x0F;
  170.     year    = ((date >> 9) & 0x7F) + 1980;
  171.     
  172.     fixdigit(days, day);
  173.     fixdigit(monts, month);
  174.     printf("%s %d/%s/%s\n",string,year,monts,days);
  175. }                       
  176.  
  177. /*---------------------------------------------------------------------*/
  178. /* setsystemtime sets the GEM system time & date from IKBD time & date */
  179. /*---------------------------------------------------------------------*/
  180. setsystemtime(time)
  181. register unsigned long time;
  182. {
  183.     int seconds, minutes, hours, day, month, year;
  184.     unsigned int GEMtime, GEMdate;    
  185.     
  186.     seconds = (time & 0x001F) << 1;
  187.     minutes = (time >> 5) & 0x3F;
  188.     hours   = (time >> 11) & 0x1F;
  189.     
  190.     day     = (time >> 16) & 0x1F;
  191.     month   = (time >> 21) & 0x0F;
  192.     year    = (time >> 25) & 0x7F;
  193.     
  194.     GEMdate = ((unsigned)year<<9)
  195.               |((unsigned)month<<5)
  196.               |(unsigned)day;        
  197.                      
  198.     GEMtime = ((unsigned)hours<<11)
  199.               |((unsigned)minutes<<5)
  200.               |((unsigned)seconds>>1); 
  201.  
  202.     Tsettime(GEMtime);
  203.     Tsetdate(GEMdate);
  204. }                       
  205.  
  206.